<?php
session_start();
require_once('../includes/DbConnector.php');
$connector  = new DbConnector();

if (isset($_POST['logInEmail']) && isset($_POST['logInPassword'])) {
        $sql = "SELECT * FROM user_account WHERE email = '{$_POST['logInEmail']}'";
	$result = $connector->query($sql);
        while($row = mysql_fetch_object($result)){
            $user = $row;
      }
	if (!empty($result)) {
            if (validate_password($_POST['logInPassword'], $user->password)) {
                // Replace with your application logic
                //header("Location: /Barcrawl/admin/barStats.php");
                $_SESSION['login'] = '1';
                $_SESSION['userId'] = $user->user_id;
                $_SESSION['username'] = $user->username;
                $_SESSION['logInEmail'] = $_POST['logInEmail'];
                $_SESSION['firstName'] = $user->first_name;
                $_SESSION['lastName'] = $user->last_name;
                die("LOGIN SUCCESS");
            }
	}
	// Replace with your application logic
	die("LOGIN FAILURE");
}
?>